layui.define([ 'form', 'laydate', 'table' ], function(exports) {
	var form = layui.form;
	var laydate = layui.laydate;
	var table = layui.table;
	var userTable = null;
	var view ={
		
		init:function(){
			this.initTable();
			this.initSearchForm();
			this.initToolBar();
			window.dataReload = function(){
				Lib.doSearchForm($("#orgSearchForm"),userTable)
			}
		},
		initTable:function(){
			userTable = table.render({
				elem : '#orgTable',
				height : Lib.getTableHeight(1),
                cellMinWidth: 100,
				method : 'post',
				url : Common.ctxPath + '/admin/org/list.json' //数据接口
				,page : {"layout":['count','prev', 'page', 'next']} //开启分页
				,limit : 10,
				cols : [ [ //表头
					{type : 'checkbox',fixed:'left'},
					{title : '序号',width : 80,fixed:'left',align:'center',toolbar : '#indexTpl',type:'numbers'},
					{field : 'code',title : '事业部代码',align : 'center',},
					{field : 'name',title : '事业部名称',align : 'center',},
					{field : 'parentOrgText', title : '所在父事业部',align : 'center',},
					{field : 'typeText',title : '事业部类型',align : 'center',},
                    {field:'userName',title:'事业部负责人',align : 'center',},
					{field : 'createTime',title : '创建时间',width : 160,sort : true,align : 'center',
						templet:function(d){
							return Common.getDate(d.createTime,'yyyy-MM-dd HH:mm:ss');
						},
					},
					{fixed : 'right', title : '操作', align : 'left', toolbar : '#toobar', width:200 }

				] ]

			});
		},
		
		initSearchForm:function(){
			Lib.initSearchForm( $("#orgSearchForm"),userTable,form);
		},
		initToolBar:function(){
			toolbar = {
					add : function() { //获取选中数据
						var url = "/admin/org/add.do";
						Common.openDlg0(url,'448px','735px',"事业部管理>新增");
					},
                batchDel : function() {
						layui.use(['del'], function(){
							  var delView = layui.del
							  delView.delBatch();
						});
					}
				};
			$('.ext-toolbar').on('click', function() {
				var type = $(this).data('type');
				toolbar[type] ? toolbar[type].call(this) : '';
			});
		}
	};
    //监听工具条
    table.on('tool(orgTable)', function(obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        if(layEvent === 'edit'){
            var url = "/admin/org/edit.do?id="+data.id;
            Common.openDlg0(url,'448px','735px',"事业部管理>"+data.name+">编辑");
        }else if(layEvent === 'del'){
            layui.use(['del'], function(){
                var delView = layui.del;
                delView.delSingle(data);
            });
        }else if(layEvent === 'orgUser'){
            var url = "/admin/org/user/list.do?orgId="+data.id;
            Common.openDlg0(url,'450px','616px',"事业部管理>"+data.name+">用户列表");
        }
    });

	 exports('index',view);
	
});